package com.tools.cleanmaster.model.language;

import android.content.Context;

import com.tools.cleanmaster.utils.LanguageHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

/**
 * 解决多语言缩写显示不统一问题
 */
public class LanguageCompat {
    private static final String TAG = "LanguageCompat";

    private static final List<String> specialList = new ArrayList<String>();

    private static final Map<String, Integer> languageMap = new HashMap<String, Integer>();

    private static final int DEFAULT_LAN = 1;

    //如果有类似下面这种语言的,请自行添加
    static {
        specialList.add("pt_BR");
        specialList.add("zh_CN");
        specialList.add("zh_TW");
    }

    static {
        languageMap.put("en", 1);
        languageMap.put("in", 2);
        languageMap.put("de", 3);
        languageMap.put("es", 4);
        languageMap.put("fr", 5);
        languageMap.put("it", 6);
        languageMap.put("pt_BR", 7);
        languageMap.put("pt", 8);
        languageMap.put("ru", 9);
        languageMap.put("tr", 10);
        languageMap.put("vi", 11);
        languageMap.put("th", 12);
        languageMap.put("ar", 13);
        languageMap.put("ja", 14);
        languageMap.put("ko", 15);
        languageMap.put("zh_CN", 16);
        languageMap.put("zh_TW", 17);
    }

    public static String getLocaleString(Context ct) {
        Locale locale = LanguageHelper.getLocale(ct);
        if (specialList.contains(locale.toString())) {
            return locale.toString();
        } else {
            return locale.getLanguage();
        }
    }

    public static int getLocaleID(String lang) {
        return languageMap.get(lang);
    }

    public static int getCurrentLocaleID(Context ct) {
        String localString = getLocaleString(ct);
        Integer index = languageMap.get(localString);
        if (null == index) {
            //使用默认英文
            return DEFAULT_LAN;
        }
        return index;
    }

}
